package com.csk.zsk.compents.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csk.zsk.compents.dao.UserDao;
import com.csk.zsk.compents.entity.User;
import com.csk.zsk.compents.service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Override
	@Transactional(readOnly = true)
	public User findUserByLoginName(String loginName) {
		return userDao.findUniqueBy("loginName", loginName);
	}

	@Override
	@Transactional(readOnly = true)
	public User getUser(String id) {
		return userDao.getIdByGetMethod(id);
	}

	@Override
	public void saveUser(User user) {
		userDao.save(user);

	}

	@Override
	@Transactional(readOnly = true)
	public boolean isLoginNameUnique(String newLoginName, String oldLoginName) {
		return userDao.isPropertyUnique("loginName", newLoginName, oldLoginName);
	}
}
